#ifndef GENIE_V_CONTROL
#define GENIE_V_CONTROL

#include "curve.h"

#define CONTROL_CYCLE   SYSTEM_CYCLE         // 10 ms
#define  OVERLOAD_FAULT_TRIP_LEVEL     110      // Trip level in percent of MaxLoad (Calibrated MaxLoad = 100%)
// ET_WORKING <AMWP_PASS_FAIL>
#define  OVERLOAD_FAULT_TRIP_LEVEL_AMWP   100      // Trip level in percent of MaxLoad (Calibrated MaxLoad = 115%)  126=x=(110*115)/100 NOT WORKING
#define OVERLOAD_FAULT_HYSTERESIS      10    // Must be less than OVERLOAD_FAULT_TRIP_LEVEL.
#define OVERLOAD_UP_OFFSET          -1    // Must be less than OVERLOAD_FAULT_TRIP_LEVEL.
#define OVERLOAD_HEIGHT_OFFSET         0//12    // Must be less than OVERLOAD_FAULT_TRIP_LEVEL.
#define OVERLOAD_UP_HEIGHT_OFFSET      0     // Must be less than OVERLOAD_FAULT_TRIP_LEVEL.
#define BLEED_TIME                  18000
#define BLEED_COMP                  20
#define BLEED_COMP_AMWP             0//10


struct LIFT_STRUCT
{
   struct curve * pDriveCurve;
   struct curve * pSteerCurve;

   UINT16 calc_pwm1;          // HD UP/LEFT/RIGHT Lift-Steer Motor
   UINT16 calc_pwm2;          // DC FWD/REV Driving Motor.
   UINT16 calc_fet;
   UINT16 hd_fet;

   INT16  nRampedCounts1;         // current joystick counts
   INT16  nRampedCounts2;         // current joystick counts
   INT32  nRampedCounts1_X_1000;
   INT32  nRampedCounts2_X_1000;

   UINT16 wOverloadCounter;
   UINT8  bModeChangeTimer;
   UINT16 wDownSafetyTimer;
   UINT16 wDownSafetyTimerStowed;
   UINT16 wUSDownDelayTimer;
   UINT16  wReverseSwitchTimer;
   UINT16  wForwardSwitchTimer;
   UINT8  bMotorOnTimer;
   UINT8  bMotorOnTimer2;
   UINT8 bLevelBrakeApplyTimer;
   UINT16  wNeutralWheelPwmOffTimer;
   UINT16  wNeutralBrakeApplyTimer;
   // UINT16  wNeutralDirectionApplyTimer;
   // UINT16  wTiltBrakeApplyTimer;

   //    lift setup timers
   UINT16 wBrakeDelay;
   UINT16 wSteeringOffDelay;
   UINT16 wDirectionDelay;
   UINT8  bMotorEnableDelay;
   UINT8  bTiltBrakeDelay;
   UINT8  bLevelBrakeDelay;
   UINT16 wOverloadStabilizationPeriod;
   UINT16 wMotorLEDCounter1;
   UINT8  bMotorFault1;
   UINT16 wMotorLEDCounter2;
   UINT8  bMotorFault2;
   INT16  nOverloadPercent;

   UINT8 fDownSafetyCheck2;
   UINT8 fDownSafetyCheck;

   UINT8 fPlatformModeFault: 1;
   UINT8 fOverload: 1;
   UINT8 fLoad99: 1;
   UINT8 fLoad90: 1;
   UINT8 fLoad80: 1;
   UINT8 fEnable: 1;
   UINT8 fHigh: 1;
   UINT8 fHighMode: 1;
   UINT8 fLiftDrive: 1;
   UINT8 fKeySwitch: 1;
   UINT8 fLiftDriveDisable: 1;
   UINT8 fMotorLED1: 1;
   UINT8 fMotorNibble1: 1;
   UINT8 fMotorValidBit1: 1;
   // UINT8 fMotorLED2:1;
   UINT8 fMotorNibble2: 1;
   UINT8 fMotorValidBit2: 1;
   UINT8 fNoFault: 1;
   UINT8 fMotorController: 1;
   UINT8 fMotorFault: 1;
   UINT8 fFootPlate: 1;
   UINT8 fEnableSafety: 1;
};


extern struct LIFT_STRUCT LIFT_Data;
extern UINT16 u16PcuNoActionCnt;

extern void ALGOR_Overload(int n_Pressure_Percent_of_Maximum);
extern void ALGOR_Lift(void);
extern void CONTROL_Setup(void);
extern void LIFT_setfets(void);
extern void LIFT_Pwm(void);
extern void MotorFaultMonitor(void);

#endif
